package b_state.b_design_patten;

/**
 * Created by wug on 2016/6/14 0014.
 */
public class StateHaveMoney implements State {
    WaterMachine waterMachine;

    public StateHaveMoney(WaterMachine waterMachine) {
        this.waterMachine = waterMachine;
    }

    @Override
    public void workerPut() {
        waterMachine.setState(new StateSoldOut(waterMachine));
        waterMachine.put();
    }

    @Override
    public void insertMoney(int num) {
        waterMachine.setState(new StateNoMoney(waterMachine));
        waterMachine.insert(num);
    }

    @Override
    public void pressSellBtn() {
//        waterMachine.setState(new StateLucky(waterMachine));
        waterMachine.setState(new StateSold(waterMachine));
        waterMachine.sell();
    }

    @Override
    public void refundRocker() {
        if (waterMachine.getMoney()>0) {
            System.out.println("退回机器中的" + waterMachine.getMoney() + "元钱。");
            waterMachine.setMoney(0);
        } else {
            System.out.println("没有钱，无法退。。。");
            waterMachine.setState(new StateNoMoney(waterMachine));
        }
    }
}
